import { Injectable, Inject } from '@angular/core';
import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';

@Injectable()
export class AuthGuardService implements CanActivate {
    constructor( @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, private router: Router) { }

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
        const token = this.tokenService.get()
        if (token && token.token) {
            return true;
        }

        console.log("未登录");
        this.router.navigateByUrl(this.tokenService.login_url);
        return false;
    }
}